package com.ruoyi.generator.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.job.TaskException;
import com.ruoyi.generator.entity.*;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.generator.service.ProjectService;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("project")
public class ProjectController extends BaseController {

    @Autowired
    private ProjectService ProjectService;

    @PostMapping("/add")
    public AjaxResult createProject(@RequestBody Project project) throws ParseException {
        int result=ProjectService.insertProject(project);
        AjaxResult ajaxResult = toAjax(result);
        System.out.println(ajaxResult);
        return toAjax( ProjectService.insertProject(project));
    }

//    @PreAuthorize("@ss.hasPermi('customer:update')")
//    @PostMapping("/update")
//    public AjaxResult updateContract(@RequestBody Contract Contract) {
//        return toAjax( ContractService.updateContractByCode(Contract));
//    }
//
//    @PreAuthorize("@ss.hasPermi('project:query')")
//    @GetMapping("/clientlist")
//    public List<Map<String, String>> clientlist() {
//        // 直接获取客户列表
//        List<Customer> customers = ContractService.selectClientlist();
//
//        // 创建一个用于返回的客户数据列表
//        List<Map<String, String>> clientList = new ArrayList<>();
//        for (Customer customer : customers) {
//            Map<String, String> clientData = new HashMap<>();
//            clientData.put("id", String.valueOf(customer.getId())); // 假设你的Contract类有getId()方法
//            clientData.put("name", customer.getCustomerName()); // 假设你的Contract类有getName()方法
//            clientData.put("code", customer.getCustomerCode()); // 假设你的Contract类有getCode()方法
//
//            clientList.add(clientData);
//        }
//
//        // 返回客户数据列表
//        return clientList;
//    }

    @GetMapping("/list")
    public TableDataInfo list(ProjectSearchCriteria projectSearchCriteria)
    {
        startPage();
        List<Project> list = ProjectService.selectProjectList(projectSearchCriteria);
        System.out.println(list);
        return getDataTable(list);
    }



    @GetMapping("/queryListByType")
    public TableDataInfo queryListByType(QuerySearch QuerySearch)
    {
        startPage();
        List<Object> list = ProjectService.selectList(QuerySearch);
        System.out.println(list);
        return getDataTable(list);
    }


    /**
     * 删除项目信息
     */
    @Log(title = "客户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String  id) throws SchedulerException, TaskException
    {
        return toAjax(ProjectService.deleteProjectById(id));
    }

}
